import java.awt.Color;


public class Plane implements Renderable{
	
	private Vector normal;
	private double offset;
	private int materialIndex;
	
	
	public Plane(double x, double y, double z, double offset, int index){
		this.normal = new Vector(x, y, z);
		normal = normal.normalizedVector();
		this.offset = offset;
		this.materialIndex = index;
	}
	
	public Vector getNormal(){
		return this.normal;
	}
	
	public double getOffset(){
		return this.offset;
	}

	@Override
	public int getMaterial(){
		return materialIndex;
	}
	
	public Vector getVector(double a, double b, Vector origin){
		
		Vector Z = normal;
		Vector X = new Vector(1,0,0).crossProduct(Z).normalizedVector();
		if(X.norm()==0) X = new Vector(0,1,0).crossProduct(Z).normalizedVector();
		Vector Y = X.crossProduct(Z).normalizedVector();
		Vector result = origin.addVectors((X.multiplyVectorByScalar(a))).addVectors((Y.multiplyVectorByScalar(b)));
		return result;
	}


	@Override
	public double intersect(Ray r) {
		
		Vector origin = r.origin;
		Vector direction = r.direction;
		
		double t = ((-1)*(origin.dotProduct(normal)) + offset) / direction.dotProduct(normal);
		if(t<0) return Double.MAX_VALUE;
		
		return t;
	
	}
	
	@Override
	public double getT(Ray ray) {
		Vector vector = ray.getDirection();
		Vector point0 = ray.getOrigin();
		double div = vector.dotProduct(getNormal());
		double num = -1*(point0.dotProduct(getNormal())- getOffset());
		return num / div;
		
	}


	

	
	
	
	
}
